public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}


class MyLinkedList {
    class ListNode{
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    ListNode head;
    ListNode tail;

    public MyLinkedList() {
        head = new ListNode();
        tail = head;
    }

    public int get(int index) {
        ListNode node = head;
        for(int i = 0; i <= index; i++){
            node = node.next;
            if(node == null){
                return -1;
            }
        }
        return node.val;
    }

    public void addAtHead(int val) {
        ListNode node = new ListNode(val, head.next);
        head.next = node;
        if(tail == head){
            tail = node;
        }
    }

    public void addAtTail(int val) {
        tail.next = new ListNode(val, null);
        tail = tail.next;
    }

    public void addAtIndex(int index, int val) {
        ListNode node = head;
        for(int i = 0; i < index; i++){
            node = node.next;
            if(node == null){
                return;
            }
        }
        node.next = new ListNode(val, node.next);
        if(node == tail){
            tail = node.next;
        }
    }

    public void deleteAtIndex(int index) {
        ListNode node = head;
        for(int i = 0; i < index; i++){
            node = node.next;
            if(node == null){
                return;
            }
        }
        if(node.next == null){
            return;
        }
        if(tail == node.next){
            tail = node;
        }
        node.next = node.next.next;
    }
}

/**
 * Your MyLinkedList object will be instantiated and called as such:
 * MyLinkedList obj = new MyLinkedList();
 * int param_1 = obj.get(index);
 * obj.addAtHead(val);
 * obj.addAtTail(val);
 * obj.addAtIndex(index,val);
 * obj.deleteAtIndex(index);
 */